package utils

import (
	"errors"
	"fmt"
	"os/exec"
	"runtime"
)

func ExecSh(cmd string) (string, error) {
	var execArg []string
	if runtime.GOOS == "windows" {
		execArg = []string{"cmd", "/C"}
	} else {
		execArg = []string{"sh", "-c"}
	}
	out, err := exec.Command(execArg[0], execArg[1], cmd).CombinedOutput()
	if err != nil {
		_ = fmt.Errorf("exec error: %s", string(out))
		return "", errors.New("'" + cmd + "' failed: " + err.Error())
	}
	return string(out), nil
}
